{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bece3cb1",
   "metadata": {},
   "source": [
    "## 3.3 Jupyter Notebook快速上手\n",
    "Jupyter Notebook是一个开源的Web应用程序，允许开发者方便的创建和共享代码文档，可以实时的编写代码块运行代码块，查看结果并可视化数据。\n",
    "- 支持markdown语法\n",
    "- 支持LaTeX公式  \n",
    "- 允许把代码写入到独立的cell中，然后单独执行，无需从头开始执行代码"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "694b4b11",
   "metadata": {},
   "source": [
    "教程结构：\n",
    "\n",
    "<img src=\"./images/3-3-1.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4edb506b",
   "metadata": {},
   "source": [
    "### 3.3.1 Jupyter Notebook的安装与运行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4374955",
   "metadata": {},
   "source": [
    "####  1. 图形化界面操作\n",
    "**默认的base环境：**\n",
    "\n",
    "安装了Anaconda后，在base环境就默认就安装了Jupyter Notebook\n",
    "\n",
    "打开Anaconda，在home界面直接点击launch运行\n",
    "\n",
    "<img src=\"./images/3-3-2.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6abe3fca",
   "metadata": {},
   "source": [
    "**创建新的虚拟环境：**\n",
    "\n",
    "打开Anaconda,在Environments界面，创建新的python虚拟环境\n",
    "\n",
    "<img src=\"./images/3-3-3.png\" width=\"60%\" ></img>\n",
    "\n",
    "然后回到home界面，点击install按钮安装Jupyter Notebook 安装完成后点击launch按钮运行\n",
    "\n",
    "<img src=\"./images/3-3-4.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b98888d2",
   "metadata": {},
   "source": [
    "#### 2. 命令行操作\n",
    "**默认的base环境：**\n",
    "\n",
    "打开Anaconda Prompt命令行，因为base环境默认已经安装了Jupyter Notebook.所以直接输入命令： jupyter notebook 运行。\n",
    "可以看到浏览器中就打开了Jupyter，如果你的浏览器没有打开Jupyter的话， 你可以将命令行中下面的这几个链接复制到浏览器中应该就能打开了 这里注意：命令行窗口不要关闭， 关闭窗口的话，服务就关闭了， 你就无法在jupyter中进行其他操作了\n",
    "\n",
    "<img src=\"./images/3-3-5.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca432fda",
   "metadata": {},
   "source": [
    "**创建新的虚拟环境：**\n",
    "\n",
    "如果你不想在base环境中运行Jupyter的话 我们先在命令行窗口中 连按两次Ctrl+c 关掉kernel与服务\n",
    "\n",
    "然后创建一个新的虚拟环境Gengzhige 大家应该没有忘记上节课讲的conda命令吧 conda create -n Gengzhige python 接着切换到Gengzhige这个虚拟环境中 使用命令：conda activate Gengzhige  新创建的Gengzhige环境，并不会默认安装Jupyter，我们使用install命令来安装： conda install jupyter notebook\n",
    "\n",
    "<img src=\"./images/3-3-6.png\" width=\"60%\" ></img>\n",
    "\n",
    "等待一会 安装完成后，我们输入 jupyter notebook 回车 就可以看到浏览器中打开了Jupyter"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08ded505",
   "metadata": {},
   "source": [
    "### 3.3.2  配置与说明\n",
    "\n",
    "#### 1. 修改打开的默认目录\n",
    "\n",
    "**方式一：**\n",
    "\n",
    "其实jupyter默认是定位到的是C:\\Users\\xxx这个路径下的目录，比如我在E盘上有一个workshop文件夹,我想让jupyter打开的是个目录怎么操作呢？\n",
    "\n",
    "在命令行中切换到E:\\workshop这个目录下\n",
    "\n",
    "<img src=\"./images/3-3-7.png\" width=\"60%\" ></img>\n",
    "\n",
    "（切换目录这里：可以直接使用cd /d 具体的目录一步切换，也可以先使用E:切换到某个盘符下，再使用cd 目录切换到目标目录）\n",
    "\n",
    "然后在workshop这个目录下输入：jupyter notebook 回车，可以看到现在jupyter显示的就是workshop这个目录了"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86e1b1a3",
   "metadata": {},
   "source": [
    "**方式二：**\n",
    "\n",
    "如果你不想每次打开jupyter的时候都要先切换磁盘位置，那么可以采用这种方式：修改配置文件。\n",
    "\n",
    "在命令行中输入： jupyter notebook --generate-config\n",
    "\n",
    "<img src=\"./images/3-3-8.png\" width=\"60%\" ></img>\n",
    "\n",
    "可以看到在此目录下C:\\Users\\kk\\ .jupyter有一个配置文件jupyter_notebook_config.py\n",
    "\n",
    "找个这个文件并打开使用ctrl+f 搜索NotebookApp.notebook_dir\n",
    "\n",
    "<img src=\"./images/3-3-10.png\" width=\"60%\" ></img>\n",
    "\n",
    "找到之后将想默认打开的目录路径这个路径 粘贴在此 例如：E:\\workshop\n",
    "\n",
    "**注意：需要这行将前面的# 注释去掉**，然后保存，最后关闭此文件。\n",
    "\n",
    "<img src=\"./images/3-3-11.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e0acd3c",
   "metadata": {},
   "source": [
    "#### 2. 关闭和退出\n",
    "使用命令行运行jupyter Notebook后\n",
    "\n",
    "在使用期间 命令行窗口不要关闭否则服务就会关闭\n",
    "\n",
    "使用完毕后，连按两次 **[Ctrl+C]** 关闭服务"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28237323",
   "metadata": {},
   "source": [
    "### 3.3.3 使用快捷键\n",
    "\n",
    "**按【H】键，会调出键盘快捷键**\n",
    "\n",
    "<img src=\"./images/3-3-12.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fc6b5a8",
   "metadata": {},
   "source": [
    "**命令行模式:**\n",
    "\n",
    "Esc键 进入命令行模式\n",
    "\n",
    "单元格左边变蓝色\n",
    "\n",
    "常用快捷键\n",
    "\n",
    "【Ctrl+Enter】：是运行选中的单元格，他会停留在此\n",
    "\n",
    "【Alt+Enter】：是运行单元格并且在下面插入一个新的单元格\n",
    "\n",
    "【Shift+Enter】:是 运行单元格, 并选择下面的单元格\n",
    "\n",
    "【Tab】键用来代码补全\n",
    "\n",
    "【A】键：above是在上面插入单元格\n",
    "\n",
    "【B】键：below 是在下面插入单元格\n",
    "\n",
    "【M】键： 是把单元格变成Markdown\n",
    "\n",
    "【Y】键：是把单元格变成代码块\n",
    "\n",
    "两下【D】键：删除选中的单元格\n",
    "\n",
    "**编辑模式:**\n",
    "Enter键 进入编辑模式\n",
    "\n",
    "常用快捷键\n",
    "\n",
    "【Ctrl+/】:代码注释\n",
    "\n",
    "【Ctrl+D】:删除整行\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "186746b8",
   "metadata": {},
   "source": [
    "### 3.3.4 常用Markdown语法\n",
    "\n",
    "<img src=\"./images/3-3-13.png\" width=\"60%\" ></img>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28fa94fc",
   "metadata": {},
   "source": [
    "粗体：使用*号\n",
    "\n",
    "使用#号代表1-6级标题 1个#号代表最大的1级标题，以此类推 6个#号 代表最小的6级标题\n",
    "\n",
    "插入链接： 中括号里是显示的文字，小括号里是具体链接\n",
    "\n",
    "插入图片： 使用!号,接着中括号里显示图片的描述，小括号里是图片的地址\n",
    "\n",
    "更多markdown语法请查看[教程](https://markdown.com.cn/)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35dd4800",
   "metadata": {},
   "source": [
    "### 3.3.5 LaTeX示例\n",
    "Jupyter还支持LaTeX\n",
    "\n",
    "注意此时单元格要切换成markdown格式\n",
    "\n",
    "在单元格中输入：`$ a^2+b^2=c^2 $`\n",
    "\n",
    "左右的$,代表这是行内公式\n",
    "\n",
    "如果左右各输入两个$$,则代表是独立公式\n",
    "\n",
    "【Ctrl+Enter】执行此单元格看效果"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5c7fe77",
   "metadata": {},
   "source": [
    "[Next: 3-4 深度学习库Pytorch安装](./3-4%20%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E5%BA%93Pytorch%E5%AE%89%E8%A3%85.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14eadb7f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
